import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.read.listener.ReadListener;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author : DuJiabao
 * @Project : online-course-project
 * @Time : 2021/4/20 23:30
 * @Desc :
 */
public class EasyExcelDemo {
  @Test
  public void testWrite() {
    List<DemoData> list = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
      list.add(new DemoData(i, "" + i));
    }
    EasyExcel.write("E:\\write.xlsx", DemoData.class).sheet("写入方法").doWrite(list);
  }

  @Test
  public void testRead() {
    EasyExcel.read("E:\\write.xlsx", DemoData.class, new AnalysisEventListener<DemoData>() {
      @Override
      public void invoke(DemoData demoData, AnalysisContext analysisContext) {
        System.out.println(demoData);
      }

      @Override
      public void invokeHead(Map<Integer, CellData> headMap, AnalysisContext context) {
        super.invokeHead(headMap, context);
        System.out.println(headMap);
      }

      @Override
      public void doAfterAllAnalysed(AnalysisContext analysisContext) {

      }
    }).sheet().doRead();
  }

}
